package org.deadline.service.config;

import java.util.List;
import org.deadline.model.config.Preference;
import org.deadline.repository.config.PreferenceRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
@Transactional
public class PreferenceServiceImpl implements PreferenceService {

	@Autowired
    PreferenceRepository preferenceRepository;

	public long countAllPreferences() {
        return preferenceRepository.count();
    }

	public void deletePreference(Preference preference) {
        preferenceRepository.delete(preference);
    }

	public Preference findPreference(Long id) {
        return preferenceRepository.findOne(id);
    }

	public List<Preference> findAllPreferences() {
        return preferenceRepository.findAll();
    }

	public List<Preference> findPreferenceEntries(int firstResult, int maxResults) {
        return preferenceRepository.findAll(new org.springframework.data.domain.PageRequest(firstResult / maxResults, maxResults)).getContent();
    }

	public void savePreference(Preference preference) {
        preferenceRepository.save(preference);
    }

	public Preference updatePreference(Preference preference) {
        return preferenceRepository.save(preference);
    }
}
